:: =============================================================================
:: Windows shell script to transfer
:: <SCP_SRC_FILE> to <SCP_HOST>/<SCP_DST_DIR>
::
:: Author: King Lung Chiu
:: =============================================================================
@echo off
SETLOCAL
set SCRIPT_DIR=%~dp0

:: ===================================================================
:: Per-deployment configs:
:: modify transfer_rifcs_cfg.bat to change default settings
call %SCRIPT_DIR%\transfer_rifcs_cfg.bat

:: ===================================================================
:: Internal script configurations: don't need to change per deployment
:: --
:: SCP local PATH info
set SCP_DIR=winscp
set PATH=%SCP_DIR%;%PATH%
:: --
:: WinSCP dependencies
set SCP_PKEY=auth\rsa-key-ohrm.ppk
set SCP_INI=%SCP_DIR%\winscp.ini


pushd %SCRIPT_DIR%

if not exist %SCP_PKEY% (
   echo.
   echo.
   echo    NOTE:
   echo    NOTE: The following SCP private key doesn't exist:
   echo    NOTE:  %SCP_PKEY%
   echo    NOTE:
   echo    NOTE: Please do the following before continuing:
   echo    NOTE: 1. generate "%SCP_PKEY%" with the bundled
   echo    NOTE:    puttygen.exe
   echo    NOTE: 2. forward your public key to the administrator of
   echo    NOTE:    %SCP_HOST%
   echo    NOTE:
   echo.
   echo.
   exit /b 1
)

if not exist %SCP_INI% (
   echo.
   echo.
   echo    NOTE:
   echo    NOTE: The first time you run this script, you'll be
   echo    NOTE: prompted to confirm the server's RSA2 key fingerprint.
   echo    NOTE:
   echo    NOTE: Type 'y' if the key finger print is:
   echo    NOTE:  %SCP_HOST_FINGERPRINT%
   echo    NOTE:
   echo.
   echo.

   winscp.com /privateKey=%SCP_PKEY% /ini=%SCP_INI% /command "open %SCP_TARGET%" "exit"
)

winscp.com /privateKey=%SCP_PKEY% /ini=%SCP_INI% /command "option batch abort" "option confirm off" "open %SCP_TARGET%" "put %SCP_SRC_FILE% %SCP_DST_DIR%" "exit"

popd
ENDLOCAL